﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using E2_WEBSITE.Code.Product;

public partial class Products_ProductDetail_description : System.Web.UI.Page
{
    private ProductController m_ProductController = new ProductController();

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.LoadComplete += new EventHandler(Page_LoadComplete);
    }

    void Page_LoadComplete(object sender, EventArgs e)
    {
        string sProductId = string.Empty;
        string sCategoryId = string.Empty;

        sCategoryId = Request.QueryString["CategoryId"];
        sProductId = Request.QueryString["ProductId"];

        if (sCategoryId != string.Empty && sProductId != string.Empty)
        {
            try
            {
                ProductInfo productInfo = m_ProductController.getProductById(int.Parse(sProductId));
                if (productInfo != null)
                {
                    TableCell tmp = Page.FindControl("lNhaSanXuat") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.NSX.TenNSX;
                    }

                    tmp = Page.FindControl("lQuocGia") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.NSX.QuocGia;
                    }

                    tmp = Page.FindControl("lNhaPhanPhoi") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.Nha_Phan_Phoi.TenNhanPhanPhoi;
                    }

                    tmp = Page.FindControl("lNgayThemSP") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.NgayThemSP.ToString("dd/MM/yyyy");
                    }

                    tmp = Page.FindControl("lMoTa") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.MoTa;
                    }

                    tmp = Page.FindControl("lSoLuongTon") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.SoLuongTon.ToString();
                    }

                    tmp = Page.FindControl("lBaoHanh") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.BaoHanh;
                    }

                    tmp = Page.FindControl("lLoaiLinhKien") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.LoaiLinhKien.ToString();
                    }

                    tmp = Page.FindControl("lKhuyenMai") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.Khuyen_Mai.HinhThuc;
                    }

                    tmp = Page.FindControl("lPhanTramGiam") as TableCell;
                    if (tmp != null)
                    {
                        tmp.Text = productInfo.Khuyen_Mai.PhanTramGiam.ToString();
                    }
                }
                else
                {
                    Label label = Page.FindControl("lError") as Label;
                    label.Text = "Không tìm thấy dữ liệu !";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
